package com.geetour.columbus.region.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geetour.columbus.common.exceptions.ServiceException;
import com.geetour.columbus.common.model.R.AreaPage;
import com.geetour.columbus.common.service.IAreaPageService;
import com.geetour.columbus.common.utils.RandomUUID;
import com.geetour.columbus.region.bo.IAreaPageBO;
import com.geetour.columbus.region.service.IAreaPageInnerService;

@Service
public class AreaPageServiceImpl implements IAreaPageService, IAreaPageInnerService {

    private IAreaPageBO areaPageBOImpl;

    @Autowired
    public void setAreaPageBOImpl(IAreaPageBO areaPageBOImpl) {
        this.areaPageBOImpl = areaPageBOImpl;
    }

    @Override
    public void insertAreaPage(AreaPage area) throws ServiceException {
        if (area == null) {
            return;
        }
        areaPageBOImpl.insertAreaPage(area);
    }

    @Override
    public int insertAreaPageNames(String province, String city, List<String> names) throws ServiceException {
        if (province == null || city == null || names == null || names.isEmpty()) {
            return -1;
        }
        List<AreaPage> areaList = new ArrayList<AreaPage>();
        for (String name : names) {
            AreaPage area = new AreaPage();
            area.setUuid(RandomUUID.code());
            area.setProvince(province);
            area.setCity(city);
            area.setName(name);
            areaList.add(area);
        }
        return areaPageBOImpl.insertAreaPageBatch(areaList);
    }

    @Override
    public int updateAreaPage(AreaPage area) throws ServiceException {
        if (area == null) {
            return -1;
        }
        return areaPageBOImpl.updateAreaPage(area);
    }

    @Override
    public int deleteAreaPage(Long id) throws ServiceException {
        if (id == null) {
            return -1;
        }
        return areaPageBOImpl.deleteAreaPageById(id);
    }

    @Override
    public AreaPage findAreaPageById(Long id) throws ServiceException {
        if (id == null) {
            return null;
        }
        return areaPageBOImpl.findAreaPageById(id);
    }

    @Override
    public List<AreaPage> findAllAreaPages() throws ServiceException {
        return areaPageBOImpl.findAllAreaPages();
    }

    @Override
    public List<AreaPage> findAreaPages(AreaPage area) throws ServiceException {
        if (area == null) {
            return null;
        }
        return areaPageBOImpl.findAreaPages(area);
    }

}
